package com.wuxiaofan.api;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuxiaofan.entity.PaymentInfo;
import com.wuxiaofan.entity.custom.PaymentInfoCustom;
import com.wuxiaofan.service.PaymentInfoService;
import com.wuxiaofan.vo.ReturnResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.swagger.annotations.Api;

@RestController
@Api("支付信息表")
@RequestMapping("/paymentInfo")
public class PaymentInfoApi {


    @Autowired
    private PaymentInfoService paymentInfoService;

    @RequestMapping("/findById/{id}")
    public ReturnResult findById(@PathVariable("id") String id){
        PaymentInfo paymentInfo = paymentInfoService.findById(id);
        return ReturnResult.success("",paymentInfo);
    }

    @RequestMapping("findByMap")
    public ReturnResult findByMap(@RequestBody JSONObject jsonObject){
        Map paraMap = new HashMap();
        paraMap.putAll(jsonObject);
        List<PaymentInfoCustom> paymentInfoCustoms = paymentInfoService.findByMap(paraMap);
        return ReturnResult.success("",paymentInfoCustoms);
    }

    @RequestMapping("all")
    public ReturnResult all(){
        Map paraMap = new HashMap();
        List<PaymentInfoCustom> paymentInfoCustoms = paymentInfoService.findByMap(paraMap);
        return ReturnResult.success("",paymentInfoCustoms);
    }

    @RequestMapping("findByPage")
    public ReturnResult findByPage(@RequestBody JSONObject jsonObject){
        Page page = new Page(jsonObject.getIntValue("current"),jsonObject.getIntValue("size"));
        Map paraMap = new HashMap();
        paraMap.putAll(jsonObject);
        IPage<PaymentInfoCustom> paymentInfoCustoms = paymentInfoService.findByMap(paraMap,page);
        return ReturnResult.success("",paymentInfoCustoms);
    }

    @RequestMapping("save")
    public ReturnResult save(@RequestBody PaymentInfo paymentInfo){
        paymentInfo = paymentInfoService.save(paymentInfo);
        return ReturnResult.success("保存成功",paymentInfo);
    }

    @RequestMapping("update")
    public ReturnResult update(@RequestBody JSONObject jsonObject){
        Map paraMap = jsonObject;
        paymentInfoService.updateMapById(paraMap);
        return ReturnResult.success("更新成功");
    }


    @RequestMapping("delById")
    public ReturnResult delById(@RequestBody JSONObject jsonObject){
        paymentInfoService.delById(jsonObject.getString("id"));
        return ReturnResult.success("删除成功");
    }


}
